<%@ include file="/html/init.jsp"%>

<%
	List<CongDanJAXB> congDanList = (List<CongDanJAXB>)portletSession.getAttribute(KSDLConstants.CONG_DAN_LIST);
	String soDinhDanh = ParamUtil.getString(request, "soDinhDanh", StringPool.BLANK);

	CongDanJAXB cdJaxb = CongDanJAXBUtil.convertDBObjectArrayToCongDanJAXB(CongDanLocalServiceUtil.findCongDanAndItsAttributesBySDDCN(soDinhDanh));
	
	Map<String, List<TruongThongTinDTO>> truongThongTinMap = null;
	
	if(null != cdJaxb){
		CongDanJAXB cdTuFileImport = (CongDanJAXB) CollectionUtils.find(congDanList, new SoDDCNPredicate(soDinhDanh));
		truongThongTinMap = CongDanJAXBUtil.checkFieldsThayDoi(cdTuFileImport, cdJaxb);
	}

	String hoVaTen = StringPool.BLANK;
	String soCMND = StringPool.BLANK;
	String diaChiThuongTru = StringPool.BLANK;
	
	HoVaTenJAXB hvt = cdJaxb.getHoVaTen();
	CMNDJAXB cmndJaxb = cdJaxb.getCmnd();
	NoiThuongTruJAXB nntJAXB = cdJaxb.getNoiThuongTru();
	
	if(null != hvt){
		hoVaTen = hvt.getHoVaTen();
	}
	
	if(null != cmndJaxb){
		soCMND = cmndJaxb.getSoCMND();
	}
	
	if(null != nntJAXB){
		diaChiThuongTru = DiaChiUtils.createBlockDiaChi(nntJAXB.getTinhId(), nntJAXB.getQuanHuyenId(), nntJAXB.getPhuongXaId(), nntJAXB.getDiaChi());
	}
	
	List<TruongThongTinDTO> listTruongThongTinDTO = new ArrayList<TruongThongTinDTO>();
	
	if(null != truongThongTinMap){
		listTruongThongTinDTO = truongThongTinMap.get(CongDanJAXBConstants.ALL);
	}
	
	int rowCount = 0;
%>

<portlet:actionURL name="submitTruongThongTin" var="submitTruongThongTinURL">
	<portlet:param name="mvcPath" value="<%=KSDLConstants.IMPORT_DAN_CU_90 %>"/>
</portlet:actionURL>

<aui:form action="<%=submitTruongThongTinURL.toString() %>" name="truongThongTinForm" method="POST">
	<aui:input name="<%= Constants.CMD %>" type="hidden" />
	
	<aui:layout>
		<aui:column columnWidth="30">
			<label for="soDDCN"><liferay-ui:message key="so-dinh-danh-ca-nhan"/></label>
		</aui:column>
		<aui:column columnWidth="70">
			<%=soDinhDanh %>
		</aui:column>
	</aui:layout>
	
	<aui:layout>
		<aui:column columnWidth="30">
			<label for="hoVaTen"><liferay-ui:message key="ho-va-ten"/></label>
		</aui:column>
		<aui:column columnWidth="70">
			<%=hoVaTen %>
		</aui:column>
	</aui:layout>
	
	<aui:layout>
		<aui:column columnWidth="30">
			<label for="so-cmnd"><liferay-ui:message key="so-cmnd"/></label>
		</aui:column>
		<aui:column columnWidth="70">
			<%=soCMND %>
		</aui:column>
	</aui:layout>
	
	<aui:layout>
		<aui:column columnWidth="30">
			<label for="so-cmnd"><liferay-ui:message key="dia-chi-thuong-tru"/></label>
		</aui:column>
		<aui:column columnWidth="70">
			<%=diaChiThuongTru %>
		</aui:column>
	</aui:layout>
	
	<!-- button block -->
	<%-- <aui:layout>
		<aui:column columnWidth="15">&nbsp;</aui:column>
		<aui:column columnWidth="85">
			<aui:button value="tim-kiem" onClick="<%= portletNamespace + \"submitContentForm(\'\"+ KSDLConstants.TIM_KIEM + \"\')\" %>" cssClass="btn-primary"/>
			<aui:button value="import-tat-ca-vao-db" onClick="<%= portletNamespace + \"submitContentForm(\'\"+ KSDLConstants.IMPORT_TAT_CA_VAO_DB + \"\')\" %>" cssClass="btn-primary"/>
			<aui:button value="in-tat-ca-thong-tin-thay-doi" onClick="<%= portletNamespace + \"submitContentForm(\'\"+ KSDLConstants.IN_TAT_CA_THONG_TIN_THAY_DOI + \"\')\" %>" cssClass="btn-primary"/>
			<aui:button value="in-tat-ca-cong-dan" onClick="<%= portletNamespace + \"submitContentForm(\'\"+ KSDLConstants.IN_TAT_CA_CONG_DAN + \"\')\" %>" cssClass="btn-primary"/>
		</aui:column>
	</aui:layout> --%>
	
	<liferay-ui:search-container
		id="danhSachDanCuSearchContainer"
		iteratorURL="<%=PortletURLUtil.getCurrent(renderRequest, renderResponse)%>"
		curParam="hoSosParam"
		emptyResultsMessage="ko-thay-doi" delta="50">
		
		<liferay-ui:search-container-results
			results="<%=ListUtil.subList(listTruongThongTinDTO, searchContainer.getStart(), searchContainer.getEnd()) %>"
			total="<%=listTruongThongTinDTO.size()%>"/> 
		
		<liferay-ui:search-container-row keyProperty="truongThongTin"
			className="qldc.pm.csdl.cd90.model.dto.TruongThongTinDTO" modelVar="truongThongTin">
			
			<%
				String giaTriHienTai = truongThongTin.getGiaTriHienTai();
				String giaTriTuFileImport = truongThongTin.getGiaTriTuFileImport();
				String tenTruong = LanguageUtil.get(portletConfig, locale, truongThongTin.getTruongThongTin());
			%>
			
			<liferay-ui:search-container-column-text cssClass="aui-w3" name="stt" value="<%= Integer.toString(searchContainer.getStart()+(++rowCount)) %>" />
			<liferay-ui:search-container-column-text name="truong-thong-tin" value="<%=tenTruong %>"/>
			<liferay-ui:search-container-column-text name="gia-tri-hien-tai" value="<%=giaTriHienTai %>" />
 			<liferay-ui:search-container-column-text name="gia-tri-tu-file-import" value="<%=giaTriTuFileImport %>" />
			
		</liferay-ui:search-container-row>
		<liferay-ui:search-iterator paginate="true"/>
	</liferay-ui:search-container>
	
	<aui:layout>
		<aui:column columnWidth="30">&nbsp;</aui:column>
		<aui:column columnWidth="70">
			<aui:button value="xuat-bang-so-sanh-ra-file" onClick="<%= portletNamespace + \"truongThongTinForm(\'\"+ KSDLConstants.XUAT_BANG_SO_SANH_RA_FILE + \"\')\" %>" cssClass="btn-primary"/>
			<aui:button value="import-tat-ca-vao-db" onClick="<%= portletNamespace + \"truongThongTinForm(\'\"+ KSDLConstants.IMPORT_TAT_CA_VAO_DB + \"\')\" %>" cssClass="btn-primary"/>
			<aui:button value="in-tat-ca-thong-tin-thay-doi" onClick="<%= portletNamespace + \"truongThongTinForm(\'\"+ KSDLConstants.IN_TAT_CA_THONG_TIN_THAY_DOI + \"\')\" %>" cssClass="btn-primary"/>
		</aui:column>
	</aui:layout>
</aui:form>

<script type="text/javascript">
window[ksdl_namespace + 'truongThongTinForm'] = function(cmd) {
	$('#' + ksdl_namespace + 'cmd').val(cmd);

	if(cmd.startsWith('<%=KSDLConstants.IN%>')){
		$('#' + ksdl_namespace + 'truongThongTinForm').attr("target", "_blank");
	} else {
		$('#' + ksdl_namespace + 'truongThongTinForm').removeAttr("target");
	}
	
	$('#' + ksdl_namespace + 'truongThongTinForm').submit();
};
</script>
